import os
import xml.etree.ElementTree as ET
print("123123")

# 标注文件夹路径
annotation_folder_path = r'D:\zhenghe_biaozhipai\leibie_modified\Annotations'

# 遍历标注文件夹中的 XML 文件
for filename in os.listdir(annotation_folder_path):
    if not filename.endswith('.xml'):
        continue

    xml_path = os.path.join(annotation_folder_path, filename)

    # 解析 XML 文件
    tree = ET.parse(xml_path)
    root = tree.getroot()

    # 修改目标标注信息
    for object_element in root.findall('object'):
        # 获取类别信息
        class_name = object_element.find('name').text

        # 修改类别信息
        if class_name == '40140003':
            object_element.find('name').text = '40140002'
        elif class_name == '40140005':
            object_element.find('name').text = '40140004'

    # 将修改后的 XML 文件保存回原路径
    tree.write(xml_path)
    print(f"Modified XML file: {filename}")